Interactive Taylor Polynomial Demonstration

Created : July 2009 (David Woods)

This notebook demonstrates the convergence of Taylor polynomials to a user selected function. The function can be chosen from the pull - down menu or can be typed in by the user. After typing in your own function be sure to click "Ok" or hit the "Enter" key on the main keyboard. Do not hit the "Enter" key on the numeric keypad.
   
   The center of the series expansion and the degree of the polynomial can be chosen using the sliders or typed in at the right of each slider. Again, do not hit the "Enter" key on the numeric keypad when manually entering these values.
  
  Only use the "Enter" key on the numeric keypad if you want to initiate changes that you have made to the notebook code itself.   If you decide to make changes to the code below,  it would be a good idea make a backup copy of the original code first.
  
  If you do not want to display the code during a classroom demonstration you can select and copy the output panel. Then open new temporary notebook and paste the output panel into it.
  
  The controls are fairly straightforward. Just play around with them and you should get the idea. If you have any questions feel free to contact Dave Woods at : dwoods1@austincc.edu

Main Code

Manipulate[

(* This section provides function choices *)
If[functionval===ToString[Sin[x],TraditionalForm],function=Sin[x]];
If[functionval===ToString[Cos[x],TraditionalForm],function=Cos[x]];
If[functionval===ToString[Tan[x],TraditionalForm],function=Tan[x]];
If[functionval===ToString[Exp[x],TraditionalForm],function=Exp[x]];If[functionval===ToString[Exp[-x^2],TraditionalForm],function=Exp[-x^2]];If[functionval===ToString[Exp[-x/5]Sin[x],TraditionalForm],function=Exp[-x/5]Sin[x]];If[functionval===ToString[(Sin[x])^2,TraditionalForm],function=(Sin[x])^2];If[functionval===ToString[Log[1+x],TraditionalForm],function=Log[1+x]];If[functionval===ToString[1/(1+x),TraditionalForm],function=1/(1+x)];
If[functionval=="Input",function=Input["Type in your own function",tempfunct];tempfunct=function;functionval=Break];
If[functionval=="break",Break];

(* This section provides output options *)
If[serieschoice==True,series=Normal[Series[function,{x,center,n}]],series=Null];
If[errorchoice==True,error=function-Normal[Series[function,{x,center,n}]],error=Null];
If[functchoice==True, f=function,f=Null];
If[shadechoice==True, shade=2,shade=1];
If[reset==True,center=0;reset=False,center=center];

(* This section produces the graphical output*)
Column[{Text@Style[Row[{Style["f",Italic],"(",Style["x",Italic],") = ",ToString[function,TraditionalForm]}],24,Blue],
Plot[Evaluate[{f,series,Abs[error]}],{x,-a[[1]]+b[[1]],a[[1]]+b[[1]]},PlotRange->{-a[[2]]+b[[2]],a[[2]]+b[[2]]},Exclusions->{6==0},ExclusionsStyle->All,Filling->{1->{{shade},{LightGreen,LightYellow}}},PlotStyle->{Thickness[.004]},ImageSize->Full,Epilog->{Green,PointSize[.014],Point[{center,function/.x->center}]}],
If[showseries==True,Pane[Text@Style[Row[{Subscript[Style["T",Bold,Italic],n],"(",Style["x",Italic],") = ",Dynamic[Normal[Series[f,{x,center,n}]]]}],"Label",13,Bold,Background->LightBlue],660]]
},Center,Spacings->0],

(* This section creates the function drop-dow menu *)
{{functionval,ToString[Sin[x],TraditionalForm],"Choose a function"},{ToString[Sin[x],TraditionalForm],ToString[Cos[x],TraditionalForm],ToString[Tan[x],TraditionalForm],ToString[Exp[x],TraditionalForm],ToString[Exp[-x^2],TraditionalForm],ToString[Exp[-x/5]Sin[x],TraditionalForm],ToString[(Sin[x])^2,TraditionalForm],ToString[Log[1+x],TraditionalForm],ToString[1/(1+x),TraditionalForm],"Input"}},

(* This section creates the other input/output controls in the panel*)
{{functchoice,True,"Function"},{True,False},ControlPlacement->Left},{{serieschoice,True,"Series"},{True,False},ControlPlacement->Left},{{errorchoice,False,"|Error|"},{True,False},ControlPlacement->Left},
{{shadechoice,False,"Shade?"},{True,False},ControlPlacement->Left},
{{showseries,False,"Show Poly?"},{True,False},ControlPlacement->Left},
{{reset,False,"Reset Center?"},{True,False},ControlPlacement->Left},
{{center,0,"Center"},-10,10,ControlType->Slider,ImageSize->600,Appearance->{"Labeled"}},
{{n,1,"Degree"},1,30,1,ImageSize->600,ControlType->Slider,Appearance->{"Labeled"}},
{{a,{5,5},"Scale"},{1/2,1/2},{10,10},ControlPlacement->Left},
{{b,{0,0},"Shift"},{-10,-10},{10,10},ControlPlacement->Left},
 ControlPlacement->Top]

Created: July 2009

This notebook demonstrates the convergence of Taylor polynomials to a user selected function. The function can be chosen from the pull-down menu or can be typed in by the user. When typing in your own function be sure to click "Ok" or hit the "Enter" key on the main keyboard. Do not hit the "Enter" key on the numeric keypad.

The center of the series expansion and the degree of the polynomial can be chosen using the sliders or typed in at the right of each slider. Again, do not hit the "Enter" key on the numeric keypad when manually entering these values.

Only use the "Enter" key on the numeric keypad if you want to initiate changes that you have made to the notebook code itself.  

If you do not want to display the code during a classroom demonstration you can select and copy the output panel. Then open new temporary notebook and paste the output panel into it.